﻿<script type="text/javascript">
    product_id = <?=$Product['Product']['id'] ?>;
    $(document).ready(function(){
        $('#tabs').tabs();
    });
</script>
<?php echo $this->Html->css('deal'); ?>
<?php echo $this->Html->css('product'); ?>
<?php echo $this->Html->css('rateit'); ?>
<?php echo $this->Html->script('product'); ?>
<?php echo $this->Html->script('cart'); ?>
<?php echo $this->Html->script('product_cart'); ?>
<?php echo $this->Html->script('facebook_functions'); ?>
<?php echo $this->Html->script('jquery.rateit.min'); ?>
<div id="main"> 
    <div class="product">
        <div id="product_desc">
            <div id="product_img">
                <div id="product_img_current">
                </div>
                <div id="product_img_list">
                    <ul>
                    </ul>
                </div>
            </div>
            <div id="product_detail">
                <div id="title">
                    <div class="button_container">
                        <?php
                            $Product['Product']['name'] = str_replace("\"", "", $Product['Product']['name']);
                            $Product['Product']['name'] = json_encode($Product['Product']['name']);
                            $Product['Product']['name'] = substr($Product['Product']['name'], 1, strlen($Product['Product']['name']) - 2);
                        ?>
                        <a href="javascript:void(0)" onclick="share_product(
                                '<?=$Product["Product"]["name"]?>',
                                'Dealcruncher is selling <?=$Product["Product"]["name"]?>. Visit our website to view the deals!',
                                'products/view/<?=$Product["Product"]["id"]?>'); return false;">Share</a>
                        <?if($showedit):?>
                            <a href="<?=$this->webroot.'deals/add/'.$Product['Product']['id']?>">Add Deal</a>
                            <a href="<?=$this->webroot.'products/edit/'. $Product['Product']['id']?>">Edit</a>
                            <a href="javascript:void(0)"
                                onclick="jqueryui_confirm(200, '<?=$this->webroot.'products/delete/'. $Product['Product']['id']?>');">
                                Delete
                            </a>
                        <?endif;?>
                    </div>
                    <div id="name" class="title">
						<h1 style="margin:0px 0px;font-size:20px"><?=$Product['Product']['name']?></h1>
                    </div>
                    <div id="company">
						<h2 style="margin:3px 0px;font-size:15px">
							by
							<a href="<?=$Product['Manufacturer']['url']?>"><?=$Product['Manufacturer']['name']?></a>
						</h2>
                    </div>
                    <div id="rating" style="height:30px;margin-top:10px">
                    </div>
                </div>
                <hr class ="divider" size ="1" noshade="noshade" >
                <?php if (isset($deals_price) && count($deals_price)) { ?>
                <div id="price">
					<span class="priceLabel">Price:</span>
					<b class="priceValue">$<?=$deals_price[0]?> - $<?=$deals_price[sizeof($deals_price)-1]?></b>
                </div>
                <?php } ?>
				<div id="status">
					<?if(isset($Product['Deal']) && count($Product['Deal']) > 0){?>
						<span style="float:left;color: #009900;font-size: 1.35em;font-weight: normal;letter-spacing: -1px;margin-right:10px;">In stock</span>
					<?}else{?>
						<span style="float:left;color: #FF0000;font-size: 1.35em;font-weight: normal;letter-spacing: -1px;margin-right:10px;">Out of stock</span>
					<?}?>
					<div class="button_container" style="float:left;">
						<a href="<?=$this->webroot.'deals/product_deals/'.$Product["Product"]["id"]?>">All Deals</a>
					</div>
				</div>
                <div id="deals" style="clear:both">
					<div class="button_container" style="float:left;margin-top:20px">
						<?
							$num_display = 0;
							foreach($deals as $deal):
								if(strcmp($deal['User']['name'], "")){
									if($num_display < 4){
										echo $this->element('deal_small',array('deal' => $deal, 'page' => 'index'));
									}
									$num_display++;
								}
							endforeach;
						?>
					</div>
                </div>
                <!--
                    <div id="status"></div>
                    <div id="seller"><ul><li id="new"></li><li id="used"></li><li id="refurbished"></li></ul></div>
                    <div id="cart"><table><tr><td><span class="button">Add to Cart</span></td><td><span class="button">Add to Wishlist</span></td></tr></table></div>
                -->
            </div>
        </div>
    </div>
    <div id="tabs" style="clear:both">
        <ul>
            <li><a href="#product_detail_description">Description</a></li>
            <li><a href="#revertBox">Comments</a></li>
            <li><a href="#suggestions">Suggestion</a></li>
        </ul>
        <div id="product_detail_description">
        </div>
        <div id="revertBox">
            <h2><? echo $comment_count;?> User comments on "<?=$Product['Product']['name']?>"</h2>
            <?
            $url='/products/view/'.$Product['Product']['id'];
            echo $this->element('comments', array('url'=>$url)) ;
            ?>
        </div>
        <div class="his" id="suggestions">
            <div id="recent">
                <h2>Recently Viewed Items</h2>
                <div id="viewed">
                    <ul>
                        <?php foreach($recently_view_products as $p) { ?>
                        <li class="vieweditem">
                            <a href="<?=$this->webroot.'products/view/'.$p['Product']['id']?>">
                                <div class="image">
                                    <?=$html->image($thumb->image('posts/'.$p['Product']['image']), 
                                        array('class' => 'bslimg', 'style' => 'width:100%;height:100%;'));?>
                                </div>
                                <div class="info">
                                    <p style="width:70%;margin-left:5%;margin-top:10%"><?=substr($p['Product']['name'], 0, 30) ?></p>
                                </div>
                            </a>
                        </li>
                        <?php } ?>
                    </ul>
                </div>
            </div>
            <div id="recommend">
                <h2>Customers who bought this item also buy</h2>
                <div id="recmdlist">
                    <ul>
                        <?php foreach($related as $product) { ?>
                            <li class="recmditem">
                                <div class="image">
                                    <?=$html->image($thumb->image('posts/'.$product['Product']['image']), 
                                        array('class' => 'bslimg', 'style' => 'width:100%;height:100%;'));?>
                                </div>
                                <div class="info">
                                    <p><?=$product['Product']['name'] ?></p>
                                </div>
                            </li>
                        <?php } ?>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="dialog-confirm">Are you sure you want to delete product : <?php echo $Product['Product']['name'] ?>?</div>
<script>
$(document).ready(function(){
    $('#rating').rateit({readonly: true, value: <?=$Product['Product']['rating'] ?>});
});
window.fbAsyncInit = function() {
    FB.init({
      appId      : '<?=FB_API_KEY?>', // App ID
      channelUrl : 'http://dealcrunch.com/dealcruncher', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    // Additional initialization code here
  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>
